package client;

import java.io.IOException;
import java.net.Socket;

/**
 * Classe CommunicationClientEnvoie
 *
 */
public class CommunicationClientEnvoie extends Thread
{	
	public boolean connection=false;
	private String email,mDp, mess, nam, fName, demande,statut,pseudo,message="",email2="";

	private int action;
	private Socket comm = null;


	char charCur[] = new char[1]; 
	
	/** Constructeur **/
	public CommunicationClientEnvoie(Socket _comm,String name, String firstName, String mail,String mDep)
	{
		comm=_comm;
		nam=name;
		fName=firstName;
	  	email=mail;
	   	mDp=mDep;
	}//fin constructeur

	
	public void run()
	{	
		while(true)
		{
			try 
			{
				switch(action)
				{
					case 1 : //Demande de Connexion
						mess="C"+email+";"+mDp+"\u0000";
						comm.getOutputStream().write(mess.getBytes());			
						action=0;
						break;
					case 2 : //Demande de liste d'amis
						mess="A"+email;
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 3 : //Demande d'inscription    					
						mess="I"+email+";"+mDp+";"+nam+";"+fName+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 4 : //Demande d'ami
						demande=mDp;
						mess="D"+email+";"+demande+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 5 : //verification des demandes
						mess="V"+email+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 6 : //recuperer des demandes
						mess="R"+email+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 7 : //oui demande
						demande=mDp;
						mess="O"+email+";"+demande+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 8 : //supprimer demande
						demande=mDp;
						mess="S"+email+";"+demande+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 9 : //déconnection du client
						mess="Z"+email+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						//on arrete le systeme
						System.exit(0);
						action=0;    					
						break;
					case 10 : //actualisation du statut chez les amis du clients
						mess="T"+email+";"+statut+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 11 : //actualisation du statut chez les amis du clients
						mess="P"+email+";"+pseudo+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
					case 12 : //envoie d'un message de email à email2
						mess="F"+email+";"+email2+";"+message+"\u0000";
						comm.getOutputStream().write(mess.getBytes());
						action=0;
						break;
				}//fin switch
			} catch (IOException e) {e.printStackTrace();}
		}//fin while
	}//fin run()



	/** Methodes get & set **/
	public int getAction() {
		return action;
	}
	public void setAction(int action) {
		this.action = action;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getmDp() {
		return mDp;
	}

	public void setmDp(String mDp) {
		this.mDp = mDp;
	}

	public String getfName() {
		return fName;
	}

	public void setfName(String fName) {
		this.fName = fName;
	}
	
	public String getNam() {
		return nam;
	}


	public String getMessage() {
		return message;
	}


	public void setMessage(String message) {
		this.message = message;
	}


	public String getEmail2() {
		return email2;
	}


	public void setEmail2(String email2) {
		this.email2 = email2;
	}


	public String getPseudo() {
		return pseudo;
	}


	public void setPseudo(String pseudo) {
		this.pseudo = pseudo;
	}
	public void setNam(String Name) {
		this.nam = Name;
	}


	public String getStatut() {
		return statut;
	}

	public void setStatut(String statut) {
		this.statut = statut;
	}

	//fin methodes get & set

}//fin classeCommunicationClientEnvoie

